<template>
  <div class="loginCont">
    <div class="particles-container"></div>
    <div class="login-content">
      <div class="login-header">
        <div class="system-title">
          <h1 class="primary-title">自定义后台系统模版12060</h1>
          <p class="secondary-title">
            Provincial platform customer inquiry system
          </p>
        </div>
      </div>

      <div class="login-card">
        <div class="card-content">
          <div class="form-header">
            <span class="form-title">账户登录</span>
            <div class="form-subtitle">欢迎回来，请登录您的账户</div>
          </div>

          <div class="form-body">
            <div class="input-group">
              <div class="input-icon">
                <span class="iconfont icon-zhanghao"></span>
              </div>
              <el-input
                v-model="account"
                class="custom-input"
                type="text"
                size="large"
                placeholder="Enter your Account"
              ></el-input>
            </div>
            <div class="input-group">
              <div class="input-icon">
                <span class="iconfont icon-mima"></span>
              </div>
              <el-input
                v-model="password"
                class="custom-input"
                type="password"
                size="large"
                show-password
                placeholder="Enter your password"
              ></el-input>
            </div>

            <div class="remember-forgot">
              <div class="remember">
                <div class="custom-checkbox" @click="toggleRemember">
                  <div class="checkbox-outer">
                    <div
                      class="checkbox-inner"
                      :class="{ active: remenberPassword }"
                    >
                      <span class="check-icon" v-if="remenberPassword">✓</span>
                    </div>
                  </div>
                  <span>记住密码</span>
                </div>
              </div>
              <div class="forgot">
                <span class="forgot-link">忘记密码?</span>
              </div>
            </div>

            <el-button
              class="login-button"
              :loading="logining"
              :disabled="logining"
              @click="loginFn"
            >
              <span class="button-text">{{
                logining ? "正在登录" : "登录"
              }}</span>
            </el-button>
          </div>
        </div>
      </div>

      <div class="contact-info">
        <div class="contact-item">
          <span class="iconfont icon-dianhua2"></span>
          <span class="contact-text">400-115-9966</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { login } from "@/http/api";
import { ElMessage, ElMessageBox } from "element-plus";

export default {
  components: {},
  data() {
    return {
      logining: false,
      account: "",
      password: "",
      remenberPassword: false,
    };
  },
  props: {},
  methods: {
    toggleRemember() {
      this.remenberPassword = !this.remenberPassword;
    },
    async loginFn() {
      if (this.account == "") {
        ElMessage({
          message: "请输入账号",
          type: "warning",
        });
        return false;
      } else if (this.password == "") {
        ElMessage({
          message: "请输入密码",
          type: "warning",
        });
        return false;
      }
      var data = {
        account: this.account,
        password: this.password,
      };
      if (!this.logining) {
        this.logining = true;
        try {
          const resData = await login(data);
          if (resData) {
            localStorage.setItem("token", resData.token);
            localStorage.setItem("loginUser", this.account);
            // 记住密码
            if (this.remenberPassword) {
              localStorage.setItem("account", this.account);
              localStorage.setItem("password", this.password);
            } else {
              localStorage.setItem("account", "");
              localStorage.setItem("password", "");
            }
            localStorage.setItem("remenberPassword", this.remenberPassword);
            ElMessage({
              message: "登录成功",
              type: "success",
            });
            setTimeout(() => {
              this.logining = false;
              this.$router.push({ path: "/homeCenter" });
            }, 1500);
          }
        } catch {}
        setTimeout(() => {
          this.logining = false;
        }, 500);
      }
    },
    registFn() {
      ElMessageBox.confirm(
        "请联系管理员注册账号(管理员电话：400-115-9966)",
        "操作提示",
        {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "Warning",
        }
      )
        .then(() => {})
        .catch((_err) => {});
    },
  },
  mounted() {},
  created() {
    if (localStorage.getItem("remenberPassword") === "true") {
      this.account = localStorage.getItem("account");
      this.password = localStorage.getItem("password");
      this.remenberPassword = true;
    }
  },
};
</script>

<style scoped lang="less">
.loginCont {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background-image: url("/img/banner.jpg");
  display: flex;
  background-size: cover;
  justify-content: center;
  align-items: center;

  .particles-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
  }

  .login-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 2;
  }

  .login-header {
    text-align: center;
    margin-bottom: 30px;
    animation: fadeInDown 0.8s ease-out;

    .logo-area {
      margin-bottom: 20px;

      .logo-image {
        max-width: 200px;
        filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.2));
      }
    }

    .system-title {
      .primary-title {
        color: #fff;
        font-size: 32px;
        font-weight: 700;
        margin: 0;
        text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
      }

      .secondary-title {
        color: rgba(255, 255, 255, 0.8);
        font-size: 16px;
        margin: 10px 0 0;
      }
    }
  }

  .login-card {
    width: 420px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    backdrop-filter: blur(10px);
    animation: fadeInUp 0.8s ease-out 0.2s both;
    transform: translateZ(0);
    position: relative;

    &:before {
      content: "";
      position: absolute;
      top: -50%;
      left: -50%;
      width: 200%;
      height: 200%;
      background: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.1) 0%,
        rgba(255, 255, 255, 0.05) 100%
      );
      transform: rotate(30deg);
      pointer-events: none;
    }

    .card-content {
      padding: 40px;
      position: relative;
    }

    .form-header {
      text-align: center;
      margin-bottom: 30px;

      .form-title {
        font-size: 24px;
        font-weight: 700;
        color: #333;
        display: block;
        margin-bottom: 10px;
        background: linear-gradient(90deg, #4b58dc, #6f7dff);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }

      .form-subtitle {
        font-size: 14px;
        color: #666;
      }
    }

    .form-body {
      .input-group {
        position: relative;
        margin-bottom: 25px;
        display: flex;
        align-items: center;
        overflow: hidden;
        border-radius: 8px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        transition: all 0.3s ease;

        &:focus-within {
          transform: translateY(-2px);
          box-shadow: 0 5px 15px rgba(75, 88, 220, 0.15);
        }

        .input-icon {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 50px;
          height: 50px;
          background: linear-gradient(135deg, #4b58dc, #6f7dff);
          color: white;
          font-size: 18px;
        }

        .el-input {
          flex: 1;
        }

        :deep(.el-input__wrapper) {
          border-radius: 0;
          box-shadow: none !important;
          padding: 0 15px;
          height: 50px;
        }

        :deep(.el-input__inner) {
          height: 50px;
          font-size: 16px;
        }
      }

      .remember-forgot {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 25px;

        .remember {
          display: flex;
          align-items: center;

          .custom-checkbox {
            display: flex;
            align-items: center;
            cursor: pointer;
            user-select: none;

            .checkbox-outer {
              width: 22px;
              height: 22px;
              border-radius: 4px;
              background: rgba(75, 88, 220, 0.1);
              display: flex;
              align-items: center;
              justify-content: center;
              margin-right: 10px;
              box-shadow: 0 2px 8px rgba(75, 88, 220, 0.1);
              transition: all 0.3s ease;
              position: relative;
              overflow: hidden;

              &:before {
                content: "";
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: radial-gradient(
                  circle,
                  rgba(75, 88, 220, 0.2) 0%,
                  transparent 70%
                );
                opacity: 0;
                transform: scale(0.5);
                transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
              }

              &:hover:before {
                opacity: 1;
                transform: scale(1.5);
              }

              .checkbox-inner {
                width: 14px;
                height: 14px;
                border-radius: 2px;
                background: transparent;
                display: flex;
                align-items: center;
                justify-content: center;
                transition: all 0.3s ease;

                &.active {
                  background: linear-gradient(135deg, #4b58dc, #6f7dff);
                  box-shadow: 0 0 10px rgba(75, 88, 220, 0.5);
                  animation: checkPulse 0.5s
                    cubic-bezier(0.175, 0.885, 0.32, 1.275);
                }

                .check-icon {
                  color: white;
                  font-size: 10px;
                  font-weight: bold;
                  transform: scale(0);
                  opacity: 0;
                  transition: all 0.2s ease;
                }

                &.active .check-icon {
                  transform: scale(1);
                  opacity: 1;
                }
              }
            }

            span {
              color: #666;
              font-size: 14px;
              transition: color 0.3s ease;
            }

            &:hover span {
              color: #4b58dc;
            }
          }

          @keyframes checkPulse {
            0% {
              transform: scale(0.8);
            }
            50% {
              transform: scale(1.2);
            }
            100% {
              transform: scale(1);
            }
          }
        }

        .forgot {
          .forgot-link {
            color: #4b58dc;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s ease;
            position: relative;

            &:after {
              content: "";
              position: absolute;
              bottom: -2px;
              left: 0;
              width: 0;
              height: 1px;
              background: #4b58dc;
              transition: width 0.3s ease;
            }

            &:hover {
              color: #6f7dff;
              text-shadow: 0 0 10px rgba(111, 125, 255, 0.3);

              &:after {
                width: 100%;
              }
            }
          }
        }
      }

      .login-button {
        width: 100%;
        height: 50px;
        background: linear-gradient(90deg, #4b58dc, #6f7dff);
        border: none;
        border-radius: 8px;
        color: white;
        font-size: 16px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        position: relative;
        overflow: visible;

        &:before {
          content: "";
          position: absolute;
          top: 0;
          left: -100%;
          width: 100%;
          height: 100%;
          background: linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.2),
            transparent
          );
          transition: all 0.6s ease;
        }

        &:hover {
          transform: translateY(-2px);
          box-shadow: 0 7px 15px rgba(75, 88, 220, 0.3);

          &:before {
            left: 100%;
          }
        }

        &:active {
          transform: translateY(1px);
        }

        .button-icon {
          font-size: 16px;
          transition: transform 0.3s ease;
        }

        &:hover .button-icon {
          transform: translateX(5px);
        }
      }
    }
  }

  .contact-info {
    margin-top: 25px;
    display: flex;
    justify-content: center;
    animation: fadeIn 1s ease-out 0.5s both;

    .contact-item {
      display: flex;
      align-items: center;
      background: rgba(255, 255, 255, 0.15);
      backdrop-filter: blur(5px);
      padding: 10px 20px;
      border-radius: 30px;
      color: white;
      font-size: 15px;
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
      transition: all 0.3s ease;

      &:hover {
        transform: translateY(-2px);
        background: rgba(255, 255, 255, 0.25);
      }

      .iconfont {
        margin-right: 10px;
        font-size: 18px;
        color: rgba(255, 255, 255, 0.9);
      }

      .contact-text {
        color: rgba(255, 255, 255, 0.9);
        font-weight: 500;
      }
    }
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
</style>
